package com.df.barcodescaning.ui;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;

import com.df.barcodescaning.MyApplication;
import com.df.barcodescaning.R;
import com.df.barcodescaning.bean.UserData;

import java.util.Timer;
import java.util.TimerTask;

public class WelcomeActivity extends AppCompatActivity {

    UserData loggedUser;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_welcome);
    }

    @Override
    protected void onResume() {
        super.onResume();

        loggedUser = MyApplication.getInstance().getLoggedUser();
        new Timer().schedule(new TimerTask() {
            @Override
            public void run() {
                handler.sendEmptyMessage(100);
            }
        }, 1500L);
    }

    Handler handler = new Handler() {

        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            if (loggedUser == null) {
                startActivity(new Intent(WelcomeActivity.this, LoginActivity.class));
            } else {
                startActivity(new Intent(WelcomeActivity.this, ItemSelectActivity.class));
            }
            finish();
        }
    };
}
